
#include "../my_ioctl_opt.h" 

#include <stdio.h> /* standard I/O */ 
#include <fcntl.h> /* open */ 
#include <unistd.h> /* close */ 
#include <stdlib.h> /* exit */ 
#include <sys/ioctl.h> /* ioctl */ 

void test_char(int fd)
{
    int ret;
    char val;

    // 1.读
    ret = ioctl(fd, E_Get_Char, &val);
    printf("ioctl get char, ret=%d, val=%c\n", ret, val);

    // 2.写
    val = 'r';
    ret = ioctl(fd, E_Set_Char, &val);
    printf("ioctl E_Set_Char, ret=%d\n", ret);
}

void test_int(int fd)
{
    int ret;
    int val;

    // 1.读
    ret = ioctl(fd, E_Get_Int, &val);
    printf("ioctl get char, ret=%d, val=0x%X\n", ret, val);

    // 2.写
    val = 0x87654321;
    ret = ioctl(fd, E_Set_Int, &val);
    printf("ioctl E_Set_Char, ret=%d\n", ret);
}

/* Main - Call the ioctl functions */
int main(void)
{
    int fd;
    fd = open(DEVICE_PATH, O_RDWR);
    if (fd < 0) {
        printf("Can't open device file: %s, error:%d\n", DEVICE_PATH,
            fd);
        exit(EXIT_FAILURE);
    }
    test_char(fd);
    test_int(fd);

    close(fd);
    return 0;
}